﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace FPC.Offer.UI.GeneralProcessor.Police_Organize
{
    /// <summary>
    /// Police_OrganizeTalbedel 的摘要说明
    /// </summary>
    public class Police_OrganizeTalbedel : IHttpHandler
    {
        FPC.Offer.Service.Police_OrganizeTalbeService s = new Service.Police_OrganizeTalbeService();
        FPC.Offer.Service.Police_FuzzTableService ss = new Service.Police_FuzzTableService();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            var Actioon = context.Request["Actioon"].ToString();
            //添加
            if (Actioon == "add")
            {
                var name = context.Request["name"].ToString();
                Model.Police_OrganizeTalbe li = new Model.Police_OrganizeTalbe();
                li.OrganizeName = name;
                li.AlarmId = 0;
                if (s.Add(li) > 0)
                {
                    context.Response.Write(1);
                }
                else
                {
                    context.Response.Write(0);
                }

            }
            //删除
            if (Actioon == "del")
            {

                var OrganizeId = Convert.ToInt32(context.Request["OrganizeId"]);
                Model.Police_OrganizeTalbe li = s.Select().Where(m => m.OrganizeId == OrganizeId).FirstOrDefault();
                li.AlarmId = -1;

                if (s.Update(li) > 0)
                {
                    context.Response.Write(1);
                }
                else
                {
                    context.Response.Write(0);
                }

            }
            //派出所名显示
            if (Actioon == "orshow")
            {
                int OrganizeId =Convert.ToInt32(context.Request["id"]);
                List<Model.Police_OrganizeTalbe> lists = s.Select().Where(m=>m.OrganizeId==OrganizeId).ToList();
                context.Response.Write(JsonConvert.SerializeObject(lists));

            }
            //下拉框显示
            if(Actioon =="fshow")
            {
                 List<Model.Police_FuzzTable> lists = ss.Select();
                 context.Response.Write(JsonConvert.SerializeObject(lists));
                
            }
            //修改
            if (Actioon == "update")
            {
                int OrganizeId = Convert.ToInt32(context.Request["id"]);
                int fid = Convert.ToInt32(context.Request["fid"]);
                Model.Police_OrganizeTalbe li=s.Select().Where(m=>m.OrganizeId==OrganizeId).FirstOrDefault();
                li.AlarmId=fid;
               if(s.Update(li)>0)
               {
                   context.Response.Write(1);
               }
                else
               {
                   context.Response.Write(0);
               }

            }
            //批删
            if (Actioon == "dels")
            {
                string OrganizeId = context.Request["OrganizeId"];

                OrganizeId = OrganizeId.Substring(0, OrganizeId.Length - 1);

                if (OrganizeId.Substring(0, 1) == ",")
                {
                    OrganizeId = OrganizeId.Substring(1, OrganizeId.Length - 1);
                }
                if (s.or_deletes(OrganizeId) > 0)
                {
                    context.Response.Write(1);
                }
                else
                {
                    context.Response.Write(0);
                }
            }


        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}